<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>dictionarymatcher.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_labs_testing_dictionarymatcher.js.html">dictionarymatcher.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2012 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Provides the built-in dictionary matcher methods like
<a name="line17"></a> *     hasEntry, hasEntries, hasKey, hasValue, etc.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>
<a name="line22"></a>goog.provide(&#39;goog.labs.testing.HasEntriesMatcher&#39;);
<a name="line23"></a>goog.provide(&#39;goog.labs.testing.HasEntryMatcher&#39;);
<a name="line24"></a>goog.provide(&#39;goog.labs.testing.HasKeyMatcher&#39;);
<a name="line25"></a>goog.provide(&#39;goog.labs.testing.HasValueMatcher&#39;);
<a name="line26"></a>
<a name="line27"></a>
<a name="line28"></a>goog.require(&#39;goog.array&#39;);
<a name="line29"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line30"></a>goog.require(&#39;goog.labs.testing.Matcher&#39;);
<a name="line31"></a>goog.require(&#39;goog.string&#39;);
<a name="line32"></a>
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * The HasEntries matcher.
<a name="line37"></a> *
<a name="line38"></a> * @param {!Object} entries The entries to check in the object.
<a name="line39"></a> *
<a name="line40"></a> * @constructor
<a name="line41"></a> * @implements {goog.labs.testing.Matcher}
<a name="line42"></a> */
<a name="line43"></a>goog.labs.testing.HasEntriesMatcher = function(entries) {
<a name="line44"></a>  /**
<a name="line45"></a>   * @type {Object}
<a name="line46"></a>   * @private
<a name="line47"></a>   */
<a name="line48"></a>  this.entries_ = entries;
<a name="line49"></a>};
<a name="line50"></a>
<a name="line51"></a>
<a name="line52"></a>/**
<a name="line53"></a> * Determines if an object has particular entries.
<a name="line54"></a> *
<a name="line55"></a> * @override
<a name="line56"></a> */
<a name="line57"></a>goog.labs.testing.HasEntriesMatcher.prototype.matches =
<a name="line58"></a>    function(actualObject) {
<a name="line59"></a>  goog.asserts.assertObject(actualObject, &#39;Expected an Object&#39;);
<a name="line60"></a>  var object = /** @type {!Object} */(actualObject);
<a name="line61"></a>  return goog.object.every(this.entries_, function(value, key) {
<a name="line62"></a>    return goog.object.containsKey(object, key) &amp;&amp;
<a name="line63"></a>           object[key] === value;
<a name="line64"></a>  });
<a name="line65"></a>};
<a name="line66"></a>
<a name="line67"></a>
<a name="line68"></a>/**
<a name="line69"></a> * @override
<a name="line70"></a> */
<a name="line71"></a>goog.labs.testing.HasEntriesMatcher.prototype.describe =
<a name="line72"></a>    function(actualObject) {
<a name="line73"></a>  goog.asserts.assertObject(actualObject, &#39;Expected an Object&#39;);
<a name="line74"></a>  var object = /** @type {!Object} */(actualObject);
<a name="line75"></a>  var errorString = &#39;Input object did not contain the following entries:\n&#39;;
<a name="line76"></a>  goog.object.forEach(this.entries_, function(value, key) {
<a name="line77"></a>    if (!goog.object.containsKey(object, key) ||
<a name="line78"></a>        object[key] !== value) {
<a name="line79"></a>      errorString += key + &#39;: &#39; + value + &#39;\n&#39;;
<a name="line80"></a>    }
<a name="line81"></a>  });
<a name="line82"></a>  return errorString;
<a name="line83"></a>};
<a name="line84"></a>
<a name="line85"></a>
<a name="line86"></a>
<a name="line87"></a>/**
<a name="line88"></a> * The HasEntry matcher.
<a name="line89"></a> *
<a name="line90"></a> * @param {string} key The key for the entry.
<a name="line91"></a> * @param {*} value The value for the key.
<a name="line92"></a> *
<a name="line93"></a> * @constructor
<a name="line94"></a> * @implements {goog.labs.testing.Matcher}
<a name="line95"></a> */
<a name="line96"></a>goog.labs.testing.HasEntryMatcher = function(key, value) {
<a name="line97"></a>  /**
<a name="line98"></a>   * @type {string}
<a name="line99"></a>   * @private
<a name="line100"></a>   */
<a name="line101"></a>  this.key_ = key;
<a name="line102"></a>  /**
<a name="line103"></a>   * @type {*}
<a name="line104"></a>   * @private
<a name="line105"></a>   */
<a name="line106"></a>  this.value_ = value;
<a name="line107"></a>};
<a name="line108"></a>
<a name="line109"></a>
<a name="line110"></a>/**
<a name="line111"></a> * Determines if an object has a particular entry.
<a name="line112"></a> *
<a name="line113"></a> * @override
<a name="line114"></a> */
<a name="line115"></a>goog.labs.testing.HasEntryMatcher.prototype.matches =
<a name="line116"></a>    function(actualObject) {
<a name="line117"></a>  goog.asserts.assertObject(actualObject);
<a name="line118"></a>  return goog.object.containsKey(actualObject, this.key_) &amp;&amp;
<a name="line119"></a>         actualObject[this.key_] === this.value_;
<a name="line120"></a>};
<a name="line121"></a>
<a name="line122"></a>
<a name="line123"></a>/**
<a name="line124"></a> * @override
<a name="line125"></a> */
<a name="line126"></a>goog.labs.testing.HasEntryMatcher.prototype.describe =
<a name="line127"></a>    function(actualObject) {
<a name="line128"></a>  goog.asserts.assertObject(actualObject);
<a name="line129"></a>  var errorMsg;
<a name="line130"></a>  if (goog.object.containsKey(actualObject, this.key_)) {
<a name="line131"></a>    errorMsg = &#39;Input object did not contain key: &#39; + this.key_;
<a name="line132"></a>  } else {
<a name="line133"></a>    errorMsg = &#39;Value for key did not match value: &#39; + this.value_;
<a name="line134"></a>  }
<a name="line135"></a>  return errorMsg;
<a name="line136"></a>};
<a name="line137"></a>
<a name="line138"></a>
<a name="line139"></a>
<a name="line140"></a>/**
<a name="line141"></a> * The HasKey matcher.
<a name="line142"></a> *
<a name="line143"></a> * @param {string} key The key to check in the object.
<a name="line144"></a> *
<a name="line145"></a> * @constructor
<a name="line146"></a> * @implements {goog.labs.testing.Matcher}
<a name="line147"></a> */
<a name="line148"></a>goog.labs.testing.HasKeyMatcher = function(key) {
<a name="line149"></a>  /**
<a name="line150"></a>   * @type {string}
<a name="line151"></a>   * @private
<a name="line152"></a>   */
<a name="line153"></a>  this.key_ = key;
<a name="line154"></a>};
<a name="line155"></a>
<a name="line156"></a>
<a name="line157"></a>/**
<a name="line158"></a> * Determines if an object has a key.
<a name="line159"></a> *
<a name="line160"></a> * @override
<a name="line161"></a> */
<a name="line162"></a>goog.labs.testing.HasKeyMatcher.prototype.matches =
<a name="line163"></a>    function(actualObject) {
<a name="line164"></a>  goog.asserts.assertObject(actualObject);
<a name="line165"></a>  return goog.object.containsKey(actualObject, this.key_);
<a name="line166"></a>};
<a name="line167"></a>
<a name="line168"></a>
<a name="line169"></a>/**
<a name="line170"></a> * @override
<a name="line171"></a> */
<a name="line172"></a>goog.labs.testing.HasKeyMatcher.prototype.describe =
<a name="line173"></a>    function(actualObject) {
<a name="line174"></a>  goog.asserts.assertObject(actualObject);
<a name="line175"></a>  return &#39;Input object did not contain the key: &#39; + this.key_;
<a name="line176"></a>};
<a name="line177"></a>
<a name="line178"></a>
<a name="line179"></a>
<a name="line180"></a>/**
<a name="line181"></a> * The HasValue matcher.
<a name="line182"></a> *
<a name="line183"></a> * @param {*} value The value to check in the object.
<a name="line184"></a> *
<a name="line185"></a> * @constructor
<a name="line186"></a> * @implements {goog.labs.testing.Matcher}
<a name="line187"></a> */
<a name="line188"></a>goog.labs.testing.HasValueMatcher = function(value) {
<a name="line189"></a>  /**
<a name="line190"></a>   * @type {*}
<a name="line191"></a>   * @private
<a name="line192"></a>   */
<a name="line193"></a>  this.value_ = value;
<a name="line194"></a>};
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * Determines if an object contains a value
<a name="line199"></a> *
<a name="line200"></a> * @override
<a name="line201"></a> */
<a name="line202"></a>goog.labs.testing.HasValueMatcher.prototype.matches =
<a name="line203"></a>    function(actualObject) {
<a name="line204"></a>  goog.asserts.assertObject(actualObject, &#39;Expected an Object&#39;);
<a name="line205"></a>  var object = /** @type {!Object} */(actualObject);
<a name="line206"></a>  return goog.object.containsValue(object, this.value_);
<a name="line207"></a>};
<a name="line208"></a>
<a name="line209"></a>
<a name="line210"></a>/**
<a name="line211"></a> * @override
<a name="line212"></a> */
<a name="line213"></a>goog.labs.testing.HasValueMatcher.prototype.describe =
<a name="line214"></a>    function(actualObject) {
<a name="line215"></a>  return &#39;Input object did not contain the value: &#39; + this.value_;
<a name="line216"></a>};
<a name="line217"></a>
<a name="line218"></a>
<a name="line219"></a>/**
<a name="line220"></a> * Gives a matcher that asserts an object contains all the given key-value pairs
<a name="line221"></a> * in the input object.
<a name="line222"></a> *
<a name="line223"></a> * @param {!Object} entries The entries to check for presence in the object.
<a name="line224"></a> *
<a name="line225"></a> * @return {!goog.labs.testing.HasEntriesMatcher} A HasEntriesMatcher.
<a name="line226"></a> */
<a name="line227"></a>function hasEntries(entries) {
<a name="line228"></a>  return new goog.labs.testing.HasEntriesMatcher(entries);
<a name="line229"></a>}
<a name="line230"></a>
<a name="line231"></a>
<a name="line232"></a>/**
<a name="line233"></a> * Gives a matcher that asserts an object contains the given key-value pair.
<a name="line234"></a> *
<a name="line235"></a> * @param {string} key The key to check for presence in the object.
<a name="line236"></a> * @param {*} value The value to check for presence in the object.
<a name="line237"></a> *
<a name="line238"></a> * @return {!goog.labs.testing.HasEntryMatcher} A HasEntryMatcher.
<a name="line239"></a> */
<a name="line240"></a>function hasEntry(key, value) {
<a name="line241"></a>  return new goog.labs.testing.HasEntryMatcher(key, value);
<a name="line242"></a>}
<a name="line243"></a>
<a name="line244"></a>
<a name="line245"></a>/**
<a name="line246"></a> * Gives a matcher that asserts an object contains the given key.
<a name="line247"></a> *
<a name="line248"></a> * @param {string} key The key to check for presence in the object.
<a name="line249"></a> *
<a name="line250"></a> * @return {!goog.labs.testing.HasKeyMatcher} A HasKeyMatcher.
<a name="line251"></a> */
<a name="line252"></a>function hasKey(key) {
<a name="line253"></a>  return new goog.labs.testing.HasKeyMatcher(key);
<a name="line254"></a>}
<a name="line255"></a>
<a name="line256"></a>
<a name="line257"></a>/**
<a name="line258"></a> * Gives a matcher that asserts an object contains the given value.
<a name="line259"></a> *
<a name="line260"></a> * @param {*} value The value to check for presence in the object.
<a name="line261"></a> *
<a name="line262"></a> * @return {!goog.labs.testing.HasValueMatcher} A HasValueMatcher.
<a name="line263"></a> */
<a name="line264"></a>function hasValue(value) {
<a name="line265"></a>  return new goog.labs.testing.HasValueMatcher(value);
<a name="line266"></a>}
</pre>


</body>
</html>
